<?php
namespace Admin\Model;
use Think\Model;
class CurrencyModel extends Model
{
    public function addCurrency()
    {
        $data = I('post.');
        unset($data['action']);
        if($_POST['action'] == 'add' | $_POST['action'] == '' ){
            unset($data['curyid']);
            $makeId = new \Org\Twitter\IdWork();
            $data['id'] = $makeId->nextId();
            $data['admin'] = $_SESSION['admin'];
            $data['createtime'] = time();
            $data['updatetime'] = time();
            $option = $this->add($data);
            $data = ['success' => 1, 'msg' => '数据添加成功','id'=>Null];
            if(!$option){
                $data = ['success' => 0, 'msg' => '数据添加失败','id'=>Null];
            }
        }else{
            $data['admin'] = $_SESSION['admin'];
            $data['updatetime'] = time();
            $option = $this
                ->where(['curyid'=>$data['curyid']])
                ->save($data);
            $data = ['success' => 1, 'msg' => '数据修改成功','id'=>$data['curyid']];
            if(!$option){
                $data = ['success' => 0, 'msg' => '数据修改失败','id'=>$data['curyid']];
            }
        }
        return $data;
    }
}

